<?php

/**
 * 专辑缩略图推荐
 * 
 * @copyright xinwei
 * @since 2012-03-22
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//专辑ID
	cgi::get($g_cgival["album_id"], "album_id", "");
	$g_cgival["album_id"] = intval($g_cgival["album_id"]);
	
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$db = new db_food_album();
	$status_db = new db_food_album_status();
	//$class_db = new db_food_album_class();
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	
	// 获取当前专辑信息
	$check[0] = $g_cgival["album_id"];
	$album_info = $db->admin_get_food_album_by_ids($check);
	
	// 异常处理
	if(empty($album_info))
	{
		throw new Exception("该专辑不存在");
	}
	if($site_id != 900 && $album_info[0]["site_id"] != $site_id)
	{
		throw new Exception("您没有操作该专辑的权限");
	}
	
	// 获取专辑微博列表
	$album_status = $status_db->admin_get_all_status_by_album_id($g_cgival["album_id"],1,1000);

	// 缩略图过滤
	/*foreach($album_status as $i => $val)
	{
		if(empty($val["status_pic"]))
			continue;
		else
			$album_status_list[] = $val;
	}*/
	foreach ($album_status as $val)
	{
		$status_ids[] = $val['status_id'];
	}

	//add 取food_status_center by renxin1 6/7
	$db_food_status_content = new db_food_status_content();
	$status_list = $db_food_status_content->admin_get_list_by_status_ids($status_ids);
	foreach ($status_list as $val)
	{
		$status_list_tmp[$val['status_id']] = $val;
	}
	foreach ($album_status as $key=>$val)
	{
		$val['status_pic'] = $status_list_tmp[$val['status_id']]['pic'];
		$album_status_list[] = $val;
	}

	$pic_count = 0;
	//已选图片张数判断
	if($g_show["album_info"]["album_big_pic"])
		$pic_count++;
	if($g_show["album_info"]["album_small_pic1"])
		$pic_count++;
	if($g_show["album_info"]["album_small_pic2"])
		$pic_count++;
	if($g_show["album_info"]["album_small_pic3"])
		$pic_count++;	
	
	//当前参数输出到页面	
	$g_show['args'] = $g_cgival;
	
	// 输出数据格式化
	$g_show["album_info"] = $album_info[0];
	$g_show["album_info"]["pic_count"] = $pic_count;
	$g_show["album_status"] = $album_status_list;
	$g_show["album_count"] = count($album_status_list);
	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album/album_thumb_rec.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	$smarty = p_get_smarty ();
	$smarty->assign ( 'g_show', $g_show );
	$smarty->display ( "foodv2/album/album_thumb_rec.html" );
}

?>